﻿using System;
using System.Windows.Forms;

namespace PrestigeViewer
{
	public class ListView : System.Windows.Forms.ListView
	{
		/// <summary>
		/// 当 ListView 在水平方向上滚动时发生。
		/// </summary>
		//public event EventHandler ScrollHorizontal;
		/// <summary>
		/// 当 ListView 在垂直方向上滚动时发生。
		/// </summary>
		public event ScrollEventHandler ScrollVertical;

		const int WM_HSCROLL = 0x0114;
		const int WM_VSCROLL = 0x0115;

		public ListView()
		{
			this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
			this.SetStyle(ControlStyles.EnableNotifyMessage, true);
		}

		protected override void OnNotifyMessage(Message message)
		{
			if (message.Msg != 0x14)
			{
				base.OnNotifyMessage(message);
			}
		}

		protected override void WndProc(ref Message message)
		{
			switch (message.Msg)
			{
				//case WM_HSCROLL:
				//	OnHScroll(this, new ScrollEventArgs());
				//	break;

				case WM_VSCROLL:
					OnVScroll(this, new ScrollEventArgs(ScrollEventType.Last, 0));
					break;
			}
			base.WndProc(ref message);
		}
		//virtual protected void OnHScroll(ListView sender, ScrollEventArgs e)
		//{
		//	if (ScrollHorizontal != null)
		//		ScrollHorizontal(this, e);
		//}
		virtual protected void OnVScroll(ListView sender, ScrollEventArgs e)
		{
			if (ScrollVertical != null)
				ScrollVertical(this, e);
		}
	}
}
